using System;
using System.Collections.Generic;
using System.Text;
using System.Collections.ObjectModel;

namespace Decav.Data
{
    /// <summary>
    /// Gets a result of paginated items from the database, including a count of how many items there are.
    /// </summary>
    /// <typeparam name="T">The type of object held in this result.</typeparam>
    [Serializable]
    public class PaginationResult<T>
    {
        public PaginationResult(IEnumerable<T> items, int curPage, int totalItemCount)
        {
            foreach (T item in items)
                _items.Add(item);

            _page = curPage;
            _totalCount = totalItemCount;
            _itemsReadOnly = new ReadOnlyCollection<T>(_items);
        }

        private readonly Collection<T> _items = new Collection<T>();
        private ReadOnlyCollection<T> _itemsReadOnly;
        private int _page;
        private int _totalCount;

        /// <summary>
        /// Gets the zero-based page that was retrieved.
        /// </summary>
        public int Page
        {
            get
            {
                return _page;
            }
        }

        /// <summary>
        /// Gets the total number of items in the data source.
        /// </summary>
        public int TotalCount
        {
            get
            {
                return _totalCount;
            }
        }

        /// <summary>
        /// Gets a oollection of the retrieved items.
        /// </summary>
        public ReadOnlyCollection<T> Items
        {
            get
            {
                return _itemsReadOnly;
            }

        }
    }
}
